<template>
  <el-container>
    <el-header>
      <el-menu mode="horizontal">
        <el-menu-item index="0">
          <nuxt-link to="/"><img src="/logo.png" alt="" /></nuxt-link>
        </el-menu-item>
        <el-menu-item>
          <nuxt-link to="/">首页</nuxt-link>
        </el-menu-item>
        <el-menu-item v-if="userInfo.id">
          <a>退出</a>
        </el-menu-item>
        <el-menu-item v-if="userInfo.id">
          <nuxt-link to="/uc">{{ userInfo.nickname }}</nuxt-link>
        </el-menu-item>
        <el-menu-item v-if="userInfo.id">
          <nuxt-link to="/editor/new">写文章</nuxt-link>
        </el-menu-item>
        <el-menu-item v-if="!userInfo.id">
          <nuxt-link to="/register">注册</nuxt-link>
        </el-menu-item>
        <el-menu-item v-if="!userInfo.id">
          <nuxt-link to="/login">登录</nuxt-link>
        </el-menu-item>
      </el-menu>
    </el-header>
    <el-main>
      <Nuxt />
    </el-main>
    <el-footer>
      <!-- Footer content -->
    </el-footer>
  </el-container>
</template>

<script>
export default {
  computed: {
    userInfo () {
      return this.$store.state.user
    }
  },
  mounted () {
    console.log(this.$store.state.user);
    this.getUserInfo()
  },
  methods: {
    getUserInfo () {
      const token = localStorage.getItem('token')
      if (token) {
        this.$store.dispatch('user/detail')
      }
    }
  }
}
</script>

<style>
html {
  font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  word-spacing: 1px;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  box-sizing: border-box;
  background:#eee;
}
.pull-right{
  float:right !important;
}
*,
*:before,
*:after {
  box-sizing: border-box;
  margin: 0;
}
.logo{
  height:37px;
}
a{
  text-decoration: none;
}
.kkb-container{
  width:980px;
  height:80vh;
  margin:0 auto;
  background: #fff;
  padding:20px;
}
.el-menu--horizontal>.el-menu-item.is-active{
  border:none;
}
</style>
